package com.shd.edanpei.ui.view;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.shd.edanpei.R;
import com.shd.edanpei.base.data.RxBusCode;
import com.shd.edanpei.base.rxbus.RxBus;
import com.shd.edanpei.base.rxbus.Subscribe;
import com.shd.edanpei.bean.OrderDetailsModel;
import com.shd.edanpei.bean.StatusBean;
import com.shd.edanpei.enums.OrderTypeEnum;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by mc on 2018/9/20.
 * 车辆订单 订单所需材料
 */

public class OrderDataView extends LinearLayout {

    private Unbinder mUnbinder;
    private OrderDetailsModel model;

    @BindView(R.id.iv_type)
    ImageView ivType;
    @BindView(R.id.tv_type)
    TextView tvType;
    @BindView(R.id.tv_status)
    TextView tvStatus;
    @BindView(R.id.tv_amount)
    TextView tvAmount;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.tv_integral)
    TextView tvIntegral;

    public OrderDataView(Context context, OrderDetailsModel model) {
        super(context);
        this.model = model;
        initView();
    }


    private void initView() {
        LayoutInflater.from(getContext()).inflate(R.layout.order_info, this);
        RxBus.get().register(this);
        mUnbinder = ButterKnife.bind(this);
        if (model.getBaseInfo().getOrderType() == OrderTypeEnum.car.getKey()) {
            ivType.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_label_car));
            tvType.setText(OrderTypeEnum.car.getValue());
        } else if (model.getBaseInfo().getOrderType() == OrderTypeEnum.house.getKey()) {
            ivType.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_label_house));
            tvType.setText(OrderTypeEnum.house.getValue());
        }else if (model.getBaseInfo().getOrderType() == OrderTypeEnum.personal.getKey()) {
            ivType.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.xinyong));
            tvType.setText(OrderTypeEnum.personal.getValue());
        }else if (model.getBaseInfo().getOrderType() == OrderTypeEnum.enterprise.getKey()) {
            ivType.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.qiye));
            tvType.setText(OrderTypeEnum.enterprise.getValue());
        }
        int status = model.getBaseInfo().getManagerStatus();
        //tvStatus.setText(StatusEnum.getManagerDes(status));
        tvAmount.setText(model.getBaseInfo().getApplyAmount());
        tvAddress.setText(model.getBaseInfo().getArea());
        tvIntegral.setText(model.getBaseInfo().getEstimatedRevenue()+"积分");
        if (model.getBaseInfo().getOrderType() == OrderTypeEnum.house.getKey()) {
            ((TextView) findViewById(R.id.tv_evaluatePrice)).setText(model.getApplyInfo().getEvaluatePrice());
        }
    }

    //刷新列表
    @Subscribe(code = RxBusCode.REFRESH_ORDER_STATUS)
    public void refreshStatus(StatusBean bean) {
        //tvStatus.setText(StatusEnum.getManagerDes(bean.getOrderStatus()));
    }

}
